<?php
namespace app\blog\controller;

use think\Controller;
use app\blog\model\Users;

class Index extends Controller
{
    public function index()
    {
        return "welcome my blog program!";
    }

    /**
     * @return mixed
     */
    public function login()
    {
        if($this->request->isPost()) {
            $param = $this->request->param();
            $param['password'] = md5($param['password']);
            $user = Users::get($param);
            if ($user) {
                /** @var TYPE_NAME $user */
                if($user->login()) {
                  $this->success('id为'.session('userInfo.id').'的用户登陆成功！','/blog/admin','',2);
              }
            } else $this->error('usernaem or password wrong!','/blog/index/login','',2);

        }
        $this->assign('pageTitle','Login');
        return $this->fetch();
    }
}
